﻿package 
{
	import flash.display.Sprite;  
	import flash.display.MovieClip;  
	import flash.net.URLLoader;  
	import flash.net.URLRequest;  
	import flash.display.Loader;  
	import flash.events.Event;  
	import flash.filters.BitmapFilter;  
	import flash.filters.DropShadowFilter;  
	import flash.text.TextFormat;  
	import flash.text.TextField;  
	import flash.text.AntiAliasType;  
	import flash.events.MouseEvent;  
	import fl.transitions.Tween;  
	import fl.transitions.easing.*;  
	import fl.transitions.TweenEvent;  
	import flash.display.MovieClip;
	import flash.display.Bitmap;
	import flash.display.BitmapData;

	
	public class Homepage extends MovieClip
	{
		var preloader = new Preloader();
		var buttonHolder = new MovieClip;
		var xml:XML;
		var bar = new Bar();
		var alphaTween:Tween;
		var widthTween:Tween;
		var xTween:Tween;
		var yTween:Tween;
		
		//button temporaries
		var tempName:String;
		var tempAddress:String;
		var tempImage:String;
		
		
		public function Homepage():void
		{			
					
			LoadXML("homepage.xml");
			
			
					
		}
		public function LoadXML(s:String):void
		{
						
			addChild(preloader);
			preloader.x = 400;
			preloader.y = 150;
			
			var urlLoader:URLLoader = new URLLoader();
			var urlReq:URLRequest = new URLRequest(s);
			urlLoader.load(urlReq);
			urlLoader.addEventListener(Event.COMPLETE, parseXML );
		}
		public function parseXML(e:Event):void
		{
			xml = new XML(e.target.data);		
			for (var i:int = 0; i < xml.Link.length(); i++)
			{			
				tempName = xml.Link[i].@Name;
				tempImage = xml.Link[i].@Image;
				tempAddress = xml.Link[i].@Address;				

				var a:Link = new Link(tempName, tempImage, tempAddress );
				a.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
				buttonHolder.addChild(a);		
				a.x = i * 100;				
			}
			removeChild(preloader);
			addChild(buttonHolder);
			addChild(bar);
			bar.y = 40;
			
			//center the buttonHolder
			buttonHolder.x = (800 - buttonHolder.width)/2;
			buttonHolder.alpha = 0;
			buttonHolder.addEventListener(MouseEvent.ROLL_OVER, rollOverMC);
			buttonHolder.addEventListener(MouseEvent.ROLL_OUT, rollOutMC);
			
			bar.alpha = 0;
		}
		public function rollOverMC(e:Event):void
		{
			alphaTween = new Tween(buttonHolder, "alpha", Regular.easeInOut, buttonHolder.alpha, 1, 1, true);
			alphaTween = new Tween(bar, "alpha", Regular.easeInOut,bar.alpha, 1, 1, true);
			
		}
		public function rollOutMC(e:Event):void
		{
			alphaTween = new Tween(buttonHolder, "alpha", Regular.easeInOut, buttonHolder.alpha, 0, 1, true);
			alphaTween = new Tween(bar, "alpha", Regular.easeInOut,bar.alpha, 0, 1, true);
		}
		public function rollOverHandler(e:Event):void
		{
			var tempx:int = e.target.x + (800 - buttonHolder.width)/2;
			var tempy:int = e.target.y + e.target.targety + 2;
			xTween = new Tween(bar, "x", Regular.easeInOut, bar.x, tempx, .75, true);
			yTween = new Tween(bar, "y", Regular.easeInOut, bar.y, tempy, .5, true);
			widthTween = new Tween(bar, "width", Regular.easeInOut, bar.width, e.target.targetw, .75, true);
			
		}
	}
}